//===============================================================================
// Microsoft patterns & practices
// Smart Client Software Factory
//===============================================================================
// Copyright (C) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

//----------------------------------------------------------------------------------------
// patterns & practices - Smart Client Software Factory - Guidance Package
//
// This file was generated by this guidance package as part of the solution template
//
// The ModuleMetadataReflectionHelper class provides a helper to retrieve module relevant information
// like dependencies and the name of the module from a given assembly
// 
// For more information see: 
// ms-help://MS.VSCC.v80/MS.VSIPCC.v80/ms.scsf.2006jun/SCSF/html/03-210-Creating%20a%20Smart%20Client%20Solution.htm
//
// Latest version of this Guidance Package: http://go.microsoft.com/fwlink/?LinkId=62182
//----------------------------------------------------------------------------------------

using System.Reflection;
using Microsoft.Practices.CompositeUI;
using System.Collections.Generic;
using System.IO;

namespace Microsoft.Practices.QuickStarts.WPFIntegration.Infrastructure.Library.Services
{
    public static class ModuleMetadataReflectionHelper
    {
        public static string GetModuleName(string assemblyFilename)
        {
            try
            {
				string assemblyFullPath = Path.GetFullPath(assemblyFilename);
				return GetModuleName(Assembly.LoadFile(assemblyFullPath));
            }
            catch
            {
                return null;
            }
        }

        public static string GetModuleName(Assembly assm)
        {
            foreach (ModuleAttribute attrib in assm.GetCustomAttributes(typeof(ModuleAttribute), false))
                return attrib.Name;

            return null;
        }

        public static IList<string> GetModuleDependencies(string assemblyFilename)
        {
            try
            {
				string assemblyFullPath = Path.GetFullPath(assemblyFilename);
				return GetModuleDependencies(Assembly.LoadFile(assemblyFullPath));
            }
            catch
            {
                return new List<string>();
            }
        }

        public static IList<string> GetModuleDependencies(Assembly assm)
        {
            List<string> results = new List<string>();

            foreach (ModuleDependencyAttribute attrib in assm.GetCustomAttributes(typeof(ModuleDependencyAttribute), false))
                results.Add(attrib.Name);

            return results;
        }
    }
}
